/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.mall.member.web.OrderDetailAction
   Module Description   :

   Date Created      : 2010/2/11
   Original Author   : andy.chuang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.mall.member.web;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.PrefixFileFilter;

import com.yaodian100.core.common.service.BaseManager;
import com.yaodian100.core.common.utils.FileUtils;
import com.yaodian100.core.common.utils.ServerValue;
import com.yaodian100.ec.member.entity.Member;
import com.yaodian100.ec.member.service.MemberService;
import com.yaodian100.ec.order.entity.Orders;
import com.yaodian100.ec.order.service.OrderService;

/**
 * @author andy.chuang
 * 
 */
public class OrderDetailAction {
	private OrderService orderService;
	private String page;
	private String orderId;
	private int productCount;
	@Resource
	private BaseManager baseMgr;

	@Resource
	private MemberService memberService;
	private Member member;
	private boolean hasSnapShot = false;

	public String getOrderId() {
		return orderId;
	}

	/**
	 * @return the page
	 */
	public String getPage() {
		return page;
	}

	public int getProductCount() {
		return productCount;
	}

	public String page() {
		String hql = "from OrderProductDetail where orderId=? and detailTp!=?";
		List paramsList = new ArrayList();
		paramsList.add(orderId);
		paramsList.add("2");
		productCount = baseMgr.countByHql(hql, paramsList.toArray()).intValue();

		IOFileFilter fileFilter = new PrefixFileFilter(orderId + "_");
		IOFileFilter dirFilter = null;

		String memberId = UserLoginData.getMemberId();
		member = memberService.get(UserLoginData.getMemberId());
		String snapShotFolder = ServerValue.getMidHtmlPath() + "member" + File.separatorChar + memberId.substring(0, 4)
				+ File.separatorChar + memberId.substring(4, 8) + File.separatorChar + memberId + File.separatorChar;
		File snapShotFolderObj = new File(snapShotFolder);
		if (snapShotFolderObj.exists()) {
			Iterator c = FileUtils.iterateFiles(snapShotFolderObj, fileFilter, dirFilter);
			if (c.hasNext()) {
				hasSnapShot = true;
			}
		}

		Orders order = orderService.get(orderId);
		if ("83".equals(order.getOrderSt())) {
			return "split";// 被拆单的原订单
		} else {
			return page;
		}
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	/**
	 * @param page the page to set
	 */
	public void setPage(String page) {
		this.page = page;
	}

	/**
	 * @return the hasSnapShot
	 */
	public boolean isHasSnapShot() {
		return hasSnapShot;
	}

	public void setProductCount(int productCount) {
		this.productCount = productCount;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

}
